<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Wap\Controller;
use Think\Controller;

/**
 * 前台公共控制器
 * 为防止多分组Controller名称冲突，公共Controller名称统一使用分组名称
 */
class HomeController extends Controller {
    
    protected function _initialize(){
        $userinfo=session ('user_auth');
        if(empty($userinfo['openid'])){
          $wx = new \Org\Wx\Wxapi;
          $config = C('WECHAT_CONF');
          $uri = "http://pai.qinhuishou.com/index.php/Wap/Public/index";
          $wx -> get_oauth2($config['appid'],$uri);
          die();
        }
        if(empty($userinfo['uid'])){
            $this->redirect('Public/bindUser');
        }

        $config=M("Config")->where(array('name'=>'WEB_SITE_TITLE'))->field('id,name,title,extra,value,type')->find();
        $this->assign('config_data',$config);
    }



    /**
     * 获取用户注册错误信息
     * @param  integer $code 错误编码
     * @return string        错误信息
     */
    public function showRegError($code = 0){
        switch ($code) {
            case -1:  $error = '用户名长度必须在16个字符以内！'; break;
            case -3:  $error = '用户名被占用！'; break;
            case -4:  $error = '密码长度必须在6-30个字符之间！'; break;
            case -9:  $error = '手机格式不正确！'; break;
            case -11: $error = '手机号被占用！'; break;
            default:  $error = '未知错误';
        }
        return $error;
    }


}
